package com.xls.app.controller;

import com.xls.app.bean.Book;
import com.xls.app.bean.Category;
import com.xls.app.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/listPageBooks")
    public Map<String,Object> listPageBooks(Integer page, Integer rows,String bname){
        Map<String,Object>  map=new HashMap<>();
        map.put("total",bookService.countBooks(bname));
        map.put("rows",bookService.listPageBooks(page,rows,bname));
        return map;
    }

    @RequestMapping("/saveBook")
    public  boolean saveBook(Book book, Category category){
        book.setCategory(category);
        return bookService.saveBook(book);
    }

    @RequestMapping("/updateBook")
    public  boolean updateBook(Book book, Category category){
        book.setCategory(category);
        return bookService.updateBook(book);
    }

    @RequestMapping("/removeBook")
    public  boolean removeBook(@RequestParam("bids[]") List<Integer>list){
        return bookService.removeBook(list);
    }
}
